package thisIsPKQ

import (
	"github.com/shopspring/decimal"
	"log"
	"strconv"
)

func CccSched()  {
	schedulingIndex,symbolsData:=GetSchd()
	for i:=0;i<len(schedulingIndex) ;i++  {

		//获取123步交易对
		step_1_symbol:=symbolsData[schedulingIndex[i].Step1Index].Symbol
		step_2_symbol:=symbolsData[schedulingIndex[i].Step2Index].Symbol
		step_3_symbol:=symbolsData[schedulingIndex[i].Step3Index].Symbol

		var  isTrue  bool
		if symbolsData[schedulingIndex[i].Step1Index].QuoteCurrency==symbolsData[schedulingIndex[i].Step3Index].QuoteCurrency {
			isTrue=true
		}else {
			isTrue=false
		}

		switch isTrue {
		//对比第一步和第三步交易计价币，例如：omgusdt omgbtc omgusdt  此时三角价格计算为sell buy buy
		case true:
			//第一步深度价格和数量
			step_1_buy_data:=PriceSched(step_1_symbol,"SELL")
				step_1_buy_price:=step_1_buy_data[0]
				step_1_buy_count:=step_1_buy_data[1]

			//第一步深度价格和数量
			step_2_sell_data:=PriceSched(step_2_symbol,"BUY")
				step_2_sell_price:=step_2_sell_data[0]
				step_2_sell_count:=step_2_sell_data[1]

			//第一步深度价格和数量
			step_3_sell_data:=PriceSched(step_3_symbol,"BUY")
				step_3_sell_price:=step_3_sell_data[0]
				step_3_sell_count:=step_3_sell_data[1]

			//套利空间计算
			v1_0 := decimal.NewFromFloat(step_1_buy_price)
			v2_0 := decimal.NewFromFloat(step_2_sell_price)
			v3_0 := decimal.NewFromFloat(step_3_sell_price)
			v2_add_v3 := v2_0.Mul(v3_0)
			v2_add_v3_sub_v1 := v2_add_v3.Sub(v1_0)
			rate := v2_add_v3_sub_v1.Div(v1_0)
			rate_float, _ := strconv.ParseFloat(rate.String(), 64)


			//下单策略
			lot:=OrderCount(step_1_buy_count,step_2_sell_count,step_3_sell_count,step_2_sell_price)
			//log.Println(step_1_symbol,"=价格：=",step_1_buy_price,"=数量：=",step_1_buy_count,"=",step_2_symbol,"=价格：=",step_2_sell_price,"=数量：=",step_2_sell_count,"=",step_3_symbol,"=价格：=",step_3_sell_price,"=数量：=",step_2_sell_count,"套利空间：", rate_float,"=====可下单数量：",lot)

			if rate_float>=0.0065 {
				log.Println("=============================================================套利空间：",rate_float)
				log.Println(step_1_symbol, "step_1_buy_price：", step_1_buy_price)
				log.Println(step_2_symbol, "step_2_sell_price：", step_2_sell_price)
				log.Println(step_3_symbol, "step_3_symbol_price：", step_3_sell_price)
				log.Println("下单数量：",lot)
				log.Println("==============================================================")
			}

		//对比第一步和第三步交易计价币，例如：omgeth omgbtc ethbtc  此时三角价格计算为sell buy sell
		default:

			//第一步深度价格和数量
			step_1_buy_data:=PriceSched(step_1_symbol,"SELL")
			step_1_buy_price:=step_1_buy_data[0]
			step_1_buy_count:=step_1_buy_data[1]

			//第一步深度价格和数量
			step_2_sell_data:=PriceSched(step_2_symbol,"BUY")
			step_2_sell_price:=step_2_sell_data[0]
			step_2_sell_count:=step_2_sell_data[1]

			//第一步深度价格和数量
			step_3_buy_data:=PriceSched(step_3_symbol,"SELL")
			step_3_buy_price:=step_3_buy_data[0]
			step_3_buy_count:=step_3_buy_data[1]

			//套利空间计算
			v1_0 := decimal.NewFromFloat(step_1_buy_price)
			v2_0 := decimal.NewFromFloat(step_2_sell_price)
			v3_0 := decimal.NewFromFloat(step_3_buy_price)
			v2_add_v3 := v2_0.Div(v3_0)
			v2_add_v3_sub_v1 := v2_add_v3.Sub(v1_0)
			rate := v2_add_v3_sub_v1.Div(v1_0)
			rate_float, _ := strconv.ParseFloat(rate.String(), 64)

			//下单策略
			//log.Println(step_1_symbol,"=价格：=",step_1_buy_price,"=数量：=",step_1_buy_count,"=",step_2_symbol,"=价格：=",step_2_sell_price,"=数量：=",step_2_sell_count,"=",step_3_symbol,"=价格：=",step_3_buy_price,"=数量：=",step_3_buy_count,"套利空间：", rate_float,"=====可下单数量：",lot)
			if rate_float>=0.0065 {
				lot:=OrderCount(step_1_buy_count,step_2_sell_count,step_3_buy_count,step_2_sell_price)
				log.Println("=============================================================",rate_float)
				log.Println(step_1_symbol, "step_1_buy_price：", step_1_buy_price)
				log.Println(step_2_symbol, "step_2_sell_price：", step_2_sell_price)
				log.Println(step_3_symbol, "step_3_buy_price：", step_3_buy_price)
				log.Println("下单数量：",lot)
				log.Println("==============================================================")
			}
		}
	}
	//price_count:=PriceSched("","")
}
